Component({
	properties: {
		mode: Number,
		goodsId: {
			type: String,
			value: "",
		},
	},
	data: {},

	methods: {
		getGoodsInfo(goodsId) {
			
			let obj = JSON.parse(tt.getStorageSync('goods'))
			console.log("商品",obj);
			return new Promise((resolve) => {
				console.log("user goodsId", goodsId);
				resolve({
					currentPrice: Number(obj.price)*100,
					minLimits: 1,
					maxLimits: 1,
					dateRule: "周--周日",
					goodsName: obj.title,
					goodsPhoto: obj.full_cover,
					// goodsLabels: [
					//   { type: "REFUND_ANYTIME" },
					//   { type: "BOOK_IN_ADVANCE", value: 98 },
					// ],
				});
			});
		},

		onError(e) {
			console.log(e.detail);
			const {
				errNo,
				errMsg
			} = e.detail;
			console.log("errNo", errNo, "errMsg", errMsg);
			if (errNo === 21514) {
				tt.showToast({
					title: "失败", // 内容
					icon: "none", // 图标
				});
			} else if (errNo === 21513) {
				tt.showToast({
					title: "获取中", // 内容
					icon: "none", // 图标
				});
			}
		},

		onPay(options) {
			console.log("查看", options);

			const {
				status,
				orderId,
				outOrderNo,
				result
			} = options.detail;
			console.log("onPay", status, orderId, outOrderNo, result);
			if (status == "fail") {
				tt.showToast({
					title: result.errMsg, // 内容
					icon: "none", // 图标
				});
			}
			tt.navigateBack();
		},

		handleRefund(event) {
			const {
				status,
				result
			} = event.detail;
			if (status === 'success') {
				const {
					refundId,
					outRefundNo
				} = result;
				console.log('发起退款成功', refundId, outRefundNo);
			} else {
				const {
					errMsg
				} = result;
				console.log('发起退款失败', errMsg);
			}
		},

		userLogin(event) {
			console.log("place order", event);
			return new Promise((resolve) => {
				tt.login({
					success() {
						tt.getUserInfo({
							success(res) {
								console.log("login success", res);
								resolve();
							},
							fail(res) {
								console.log("fail", res);
								tt.openSetting({
									success: (res) => {
										console.log("打开设置页面成功: ", res
											.errMsg);
									},
									fail: (res) => {
										console.log("打开设置页面失败: ", res
											.errMsg);
									},
									complete: (res) => {
										console.log("接口已调用: ", res.errMsg);
									},
								});
							},
						});
					},
					// setTimeout(() => {
					//   resolve();
					// }, 0);
				});
			});
		},
	},
});